<?php
/*
 * 2021/7/15
 * 11:43
 * User: 2650332702@qq.com
 */

namespace App\Api\Controllers;


use App\Api\Manages\CommonController;
use App\Api\Models\Seckill;
use App\Api\Repositories\SeckillRepositorie;
use App\Api\Services\JsonService;
use Illuminate\Http\Request;

class SeckillController extends CommonController
{

    //分页数
    protected $pagesize;
    public function __construct()
    {
        $this->pagesize = config('page.pagesize');
    }

    public function seckillList()
    {
        $allow_field = [
            'id',
            'seckill_name',
            'seckill_info',
            'images',
            'price',
            'status',
            'start_time',
            'end_time',
            'stock',
            'paid_num'
        ];
        $where = 'start_time';
        $data = Seckill::DataSorting($allow_field,$this->pagesize,$where);
        return $this->PagingData($data);
    }

    //实时热抢
    public function hotRush()
    {
        $allow_field = [
            'id',
            'seckill_name',
            'seckill_info',
            'images',
            'price',
            'status',
            'start_time',
            'end_time',
            'stock',
            'paid_num'
        ];
        $where = 'paid_num';
        $data = Seckill::DataSorting($allow_field,$this->pagesize,$where);
        return $this->PagingData($data);
    }

    //商品详情
    public function getDetail(Request $request)
    {
        $res = $request->validate([
            'seckill_id' => ['required'],
        ]);
        $allow_field = [
            'goods_image',
            'goods_introduction',
            'price',
            'goods_content',
            'evaluate_id'
        ];
        $seckill_id = $res['seckill_id'];
        $seckill = SeckillRepositorie::OnceSeckill($seckill_id,$allow_field);
        $comments = SeckillRepositorie::getComments($seckill['evaluate_id']);
        return JsonService::success(['seckill'=>$seckill,'comments'=>$comments]);
    }
}























